<script lang="ts" setup>
import { computed } from 'vue'

const props = withDefaults(
  defineProps<{
    open?: boolean
    title?: string
  }>(),
  {
    open: false,
  },
)

const emits = defineEmits(['update:open', 'confirm'])

const openValue = computed<boolean>({
  get() {
    return props.open
  },
  set(val) {
    emits('update:open', val)
  },
})

// 确认
function onConfirm() {
  emits('confirm')
}

// 取消
function onCancel() {
  openValue.value = false
}
</script>

<template>
  <a-modal
    :open="openValue"
    :title="title"
    @ok="onConfirm"
    @cancel="onCancel"
  >
    <slot />
  </a-modal>
</template>
